package com.txsj.scan.utils;

/**
 * Created by wwb on 2017/3/06.
 * Toast工具类
 */

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.txsj.scan.MyApplication;
import com.txsj.scan.R;


/**
 * Created by wwb on 2016/12/7.
 * Toast弹出背景颜色 自定义
 */
public class ToastUtils {

    public static void t(Context context, String msg) {
        View toastRoot = LayoutInflater.from(context).inflate(R.layout.view_toast, null);
        Toast toast = new Toast(context);
        toast.setView(toastRoot);
        toast.setGravity(Gravity.CENTER, 0, 0);
        TextView tv = (TextView) toastRoot.findViewById(R.id.tv_toast_msg);
        tv.setText(msg);
        toast.show();
    }
    public static void showToast(String msg) {
        View toastRoot = LayoutInflater.from(MyApplication.getInstance()).inflate(R.layout.view_toast, null);
        Toast toast = new Toast(MyApplication.getInstance());
        toast.setView(toastRoot);
        toast.setGravity(Gravity.CENTER, 0, 0);
        TextView tv = (TextView) toastRoot.findViewById(R.id.tv_toast_msg);
        tv.setText(msg);
        toast.show();
    }

    /**
     * 长吐司
     */
    public static void t(Context context, String msg, int time) {
        View toastRoot = LayoutInflater.from(context).inflate(R.layout.view_toast, null);
        Toast toast = new Toast(context);
        toast.setView(toastRoot);
        toast.setGravity(Gravity.CENTER, 0, 0);
        TextView tv = (TextView) toastRoot.findViewById(R.id.tv_toast_msg);
        tv.setText(msg);
        toast.setDuration(time);
        toast.show();
    }


    /**
     * 网络异常提示 Toast
     */
    public static void t() {
        Context context = MyApplication.getInstance();
        View toastRoot = LayoutInflater.from(context).inflate(R.layout.view_toast, null);
        Toast toast = new Toast(context);
        toast.setView(toastRoot);
        toast.setGravity(Gravity.CENTER, 0, 0);
        TextView tv = (TextView) toastRoot.findViewById(R.id.tv_toast_msg);
        tv.setText(context.getResources().getString(R.string.net_error_info));
        toast.show();
    }
}